﻿// See https://aka.ms/new-console-template for more information
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Reflection.Metadata.Ecma335;
using System.Security.Cryptography.X509Certificates;

namespace GenerList
{
    public class Node<T>
    {
        public Node<T> Next { get; set; }
        public T Data { get; set; }
        public Node(T t)
        {
            Next = null;
            Data = t;
        }
    }


    public class GenericList<T> : IEnumerable
    {
        private Node<T> head;
        private Node<T> tail;
        public GenericList()
        {
            tail = head = null;
        }
        public Node<T> Head
        {
            get => head;
        }

        public void Add(T t)
        {
            Node<T> n = new Node<T>(t);
            if (tail == null)
            {
                head = tail = n;
            }
            else
            {
                tail.Next = n;
                tail = n;
            }
        }
        public IEnumerator GetEnumerator()
        {
            Node<T> n = head;
            while (n != null)
            {
                yield return n.Data;
                n = n.Next;
            }
        }
    }
    public class Program
    {
        const int INF = 0x3f3f3f3f;
        static void Main(string[] args)
        {
            GenericList<int> intlist = new GenericList<int>();
            for (int x = 0; x < 10; ++x) 
            { 
                intlist.Add(x);
            }

            int ma = -INF;
            int mi = INF;
            int sum = 0;
            Action<int> getSum = (m => sum += m);
            foreach (int i in intlist)
            {
                Console.WriteLine(i);
                ma = (ma > i) ? ma : i;
                mi = (mi > i) ? i : mi;
                getSum(i);
            }
            
            Console.WriteLine(ma);
            Console.WriteLine(mi);
            Console.WriteLine(sum);
        }
    }
}